<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>Modbus协议 —— ModbusTCP - 陈的错题集</title><meta name="Description" content="陈的错题集 - 个人笔记"><meta property="og:title" content="Modbus协议 —— ModbusTCP" />
<meta property="og:description" content="Modbus 是一项应用层报文传输协议，用于在通过不同类型的总线或网络连接的设备之间的客户机/服务器通信。常用于串口、以太网上的数据传输。 ADU：应用数" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://example.com/modbustcp/" /><meta property="og:image" content="https://example.com/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2023-08-23T20:05:55+08:00" />
<meta property="article:modified_time" content="2023-08-23T20:05:55+08:00" /><meta property="og:site_name" content="陈的错题集" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://example.com/logo.png"/>

<meta name="twitter:title" content="Modbus协议 —— ModbusTCP"/>
<meta name="twitter:description" content="Modbus 是一项应用层报文传输协议，用于在通过不同类型的总线或网络连接的设备之间的客户机/服务器通信。常用于串口、以太网上的数据传输。 ADU：应用数"/>
<meta name="application-name" content="陈的错题集">
<meta name="apple-mobile-web-app-title" content="陈的错题集"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://example.com/modbustcp/" /><link rel="prev" href="https://example.com/modbus/" /><link rel="next" href="https://example.com/ethercat_01summary/" /><link rel="stylesheet" href="/css/style.min.css"><link rel="preload" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
        <noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.1.1/css/all.min.css"></noscript><link rel="preload" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.1/animate.min.css" as="style" onload="this.onload=null;this.rel='stylesheet'">
        <noscript><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@4.1.1/animate.min.css"></noscript><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "Modbus协议 —— ModbusTCP",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/example.com\/modbustcp\/"
        },"image": ["https:\/\/example.com\/images\/Apple-Devices-Preview.png"],"genre": "posts","keywords": "modbus","wordcount":  1914 ,
        "url": "https:\/\/example.com\/modbustcp\/","datePublished": "2023-08-23T20:05:55+08:00","dateModified": "2023-08-23T20:05:55+08:00","publisher": {
            "@type": "Organization",
            "name": "xxxx","logo": "https:\/\/example.com\/images\/avatar.png"},"author": {
                "@type": "Person",
                "name": "Jacob Chen"
            },"description": ""
    }
    </script></head>
    <body data-header-desktop="fixed" data-header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="陈的错题集">💻陈的错题集</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 📜归档 </a><a class="menu-item" href="/tags/"> 🏷️标签 </a><a class="menu-item" href="/categories/"> 📂分类 </a><a class="menu-item" href="/about/"> ⭐关于 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder=" " id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
                </a></div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="陈的错题集">💻陈的错题集</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder=" " id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw" aria-hidden="true"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw" aria-hidden="true"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin" aria-hidden="true"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">📜归档</a><a class="menu-item" href="/tags/" title="">🏷️标签</a><a class="menu-item" href="/categories/" title="">📂分类</a><a class="menu-item" href="/about/" title="">⭐关于</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw" aria-hidden="true"></i>
            </a></div>
    </div>
</header><div class="search-dropdown desktop">
        <div id="search-dropdown-desktop"></div>
    </div>
    <div class="search-dropdown mobile">
        <div id="search-dropdown-mobile"></div>
    </div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animate__animated animate__flipInX">Modbus协议 —— ModbusTCP</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel="author" class="author"><i class="fas fa-user-circle fa-fw" aria-hidden="true"></i>Jacob Chen</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/%E9%80%9A%E8%AE%AF/"><i class="far fa-folder fa-fw" aria-hidden="true"></i>通讯</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw" aria-hidden="true"></i>&nbsp;<time datetime="2023-08-23">2023-08-23</time>&nbsp;<i class="fas fa-pencil-alt fa-fw" aria-hidden="true"></i>&nbsp;约 1914 字&nbsp;
                <i class="far fa-clock fa-fw" aria-hidden="true"></i>&nbsp;预计阅读 4 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  data-kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right" aria-hidden="true"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#tcpip上的实现-modbustcp">TCP/IP上的实现 ModbusTCP</a>
      <ul>
        <li><a href="#数据帧格式">数据帧格式</a>
          <ul>
            <li><a href="#事务元标识符">事务元标识符</a></li>
            <li><a href="#协议标识符">协议标识符</a></li>
            <li><a href="#数据长度">数据长度</a></li>
            <li><a href="#单元标识符站号">单元标识符（站号）</a></li>
            <li><a href="#功能码">功能码</a></li>
          </ul>
        </li>
        <li><a href="#功能码-0x03-命令格式解析">功能码 0x03 命令格式解析</a>
          <ul>
            <li><a href="#eg使用-功能码0x03-读取-站号01-地址0x00000x0009-的数据">eg.使用 功能码0x03 读取 站号01 地址0x0000~0x0009 的数据</a></li>
          </ul>
        </li>
        <li><a href="#功能码-0x10-命令格式解析">功能码 0x10 命令格式解析</a>
          <ul>
            <li><a href="#eg使用-功能码0x10-写入-站号01-地址0x00000x0009-的数据">eg.使用 功能码0x10 写入 站号01 地址0x0000~0x0009 的数据</a></li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><!-- # Modbus 协议 -->
<blockquote>
<p>Modbus 是一项应用层报文传输协议，用于在通过不同类型的总线或网络连接的设备之间的客户机/服务器通信。常用于串口、以太网上的数据传输。</p>
</blockquote>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Modbus%e5%b8%a7%e6%a0%bc%e5%bc%8f.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Modbus%e5%b8%a7%e6%a0%bc%e5%bc%8f.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Modbus%e5%b8%a7%e6%a0%bc%e5%bc%8f.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/Modbus%e5%b8%a7%e6%a0%bc%e5%bc%8f.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/Modbus帧格式.png"
        title="Modbus数据帧格式" /></p>
<ul>
<li><em>ADU：应用数据单元。最大不超过256个字节。一次Modbus通讯报文，可以被成为1个ADU。</em></li>
<li><em>PDU：协议数据单元。指代Modbus通讯报文中的 <strong>功能码 + 数据</strong></em></li>
</ul>
<h2 id="tcpip上的实现-modbustcp">TCP/IP上的实现 ModbusTCP</h2>
<h3 id="数据帧格式">数据帧格式</h3>
<table>
<thead>
<tr>
<th>事务元标识符</th>
<th>协议标识符</th>
<th>数据长度</th>
<th>单元标识符（站号）</th>
<th>功能码</th>
<th>数据</th>
</tr>
</thead>
<tbody>
<tr>
<td>2 byte</td>
<td>2 byte</td>
<td>2 byte</td>
<td>1 byte</td>
<td>1 byte</td>
<td>* byte</td>
</tr>
</tbody>
</table>
<p>注：</p>
<ul>
<li>MBAP报文头：事务元标识符 + 协议标识符 + 数据长度 + 单元标识符（站号）</li>
<li>ModbusTCP通过TCP/IP协议进行数据校验，故Modbus数据帧无需校验</li>
</ul>
<h4 id="事务元标识符">事务元标识符</h4>
<p>用于事务处理配对。在响应中，Modbus服务器复制请求的事务处理标识符。一般为每条报文都自加1。如果保持不变，从站也可以正常识别该报文。</p>
<h4 id="协议标识符">协议标识符</h4>
<p>用于系统内的多路复用。0 代表Modbus协议。</p>
<h4 id="数据长度">数据长度</h4>
<p>单元标识符（站号） + 功能码 + 数据 所包含的字节数</p>
<h4 id="单元标识符站号">单元标识符（站号）</h4>
<table>
<thead>
<tr>
<th>广播地址</th>
<th>从站地址</th>
<th>保留</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>1~247</td>
<td>248~255</td>
</tr>
</tbody>
</table>
<ul>
<li>因为ModbusTCP一般使用IP进行定位，所以站号在一般应用中基本失去了其作用。大部分ModbusTCP从站会忽略站号，也有小部分从站会进行站号校验。</li>
</ul>
<h4 id="功能码">功能码</h4>
<table>
<thead>
<tr>
<th>功能描述</th>
<th>功能码（十进制）</th>
<th>功能码（十六进制）</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>读线圈</strong></td>
<td><strong>01</strong></td>
<td><strong>0x01</strong></td>
<td>常用</td>
</tr>
<tr>
<td>写单个线圈</td>
<td>05</td>
<td>0x05</td>
<td></td>
</tr>
<tr>
<td>写多个线圈</td>
<td>15</td>
<td>0x0F</td>
<td></td>
</tr>
<tr>
<td>读输入寄存器</td>
<td>04</td>
<td>0x04</td>
<td></td>
</tr>
<tr>
<td><strong>读保持寄存器</strong></td>
<td><strong>03</strong></td>
<td><strong>0x03</strong></td>
<td>常用</td>
</tr>
<tr>
<td>写单个保持寄存器</td>
<td>06</td>
<td>0x06</td>
<td></td>
</tr>
<tr>
<td><strong>写多个保持寄存器</strong></td>
<td><strong>16</strong></td>
<td><strong>0x10</strong></td>
<td>常用</td>
</tr>
<tr>
<td>读/写多个保持寄存器</td>
<td>23</td>
<td>0x17</td>
<td></td>
</tr>
</tbody>
</table>
<h3 id="功能码-0x03-命令格式解析">功能码 0x03 命令格式解析</h3>
<p>请求命令格式</p>
<table>
<thead>
<tr>
<th></th>
<th>大小</th>
<th>取值范围</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>事务元标识符</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>协议标识符</td>
<td>2 byte</td>
<td>固定值0x0000</td>
<td>Modbus协议</td>
</tr>
<tr>
<td>数据长度</td>
<td>2 byte</td>
<td>0x0003 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>单元标识符（站号）</td>
<td>1 byte</td>
<td>0x01 至 0xFF</td>
<td>默认值为1，一般无需变化</td>
</tr>
<tr>
<td>功能码</td>
<td>1 byte</td>
<td>0x03</td>
<td></td>
</tr>
<tr>
<td>起始地址</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>寄存器数量（N）</td>
<td>2 byte</td>
<td>0x0000 至 0x007D</td>
<td></td>
</tr>
</tbody>
</table>
<p>响应命令格式</p>
<table>
<thead>
<tr>
<th></th>
<th>大小</th>
<th>取值范围</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>事务元标识符</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td>复制自请求命令</td>
</tr>
<tr>
<td>协议标识符</td>
<td>2 byte</td>
<td>固定值0x0000</td>
<td>Modbus协议</td>
</tr>
<tr>
<td>数据长度</td>
<td>2 byte</td>
<td>0x0003 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>单元标识符（站号）</td>
<td>1 byte</td>
<td>0x01 至 0xFF</td>
<td>默认值为1，一般无需变化</td>
</tr>
<tr>
<td>功能码</td>
<td>1 byte</td>
<td>0x03</td>
<td></td>
</tr>
<tr>
<td>字节数</td>
<td>1 byte</td>
<td>2 * N</td>
<td>寄存器值所包括的字节数</td>
</tr>
<tr>
<td>寄存器值</td>
<td>2 * N byte</td>
<td>数据值</td>
<td>1个寄存器占用2个字节</td>
</tr>
</tbody>
</table>
<p><strong>注：<em>N = 寄存器数量</em></strong></p>
<p>错误响应格式</p>
<table>
<thead>
<tr>
<th></th>
<th>大小</th>
<th>取值范围</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>事务元标识符</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td>复制自请求命令</td>
</tr>
<tr>
<td>协议标识符</td>
<td>2 byte</td>
<td>固定值0x0000</td>
<td>Modbus协议</td>
</tr>
<tr>
<td>数据长度</td>
<td>2 byte</td>
<td>0x0003 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>单元标识符（站号）</td>
<td>1 byte</td>
<td>0x01 至 0xFF</td>
<td>默认值为1，一般无需变化</td>
</tr>
<tr>
<td>错误码</td>
<td>1 byte</td>
<td>0x83</td>
<td>0x80 + 0x03</td>
</tr>
<tr>
<td>异常码</td>
<td>1 byte</td>
<td>0x01 至 0x04</td>
<td>0x01：该功能码不支持 <br/> 0x02：起始地址不支持 或者 起始地址+寄存器数量不支持 <br/> 0x03：读取寄存器数量不支持 <br/> 0x04：读取寄存器失败</td>
</tr>
</tbody>
</table>
<h4 id="eg使用-功能码0x03-读取-站号01-地址0x00000x0009-的数据">eg.使用 功能码0x03 读取 站号01 地址0x0000~0x0009 的数据</h4>
<p>请求命令：SEND <strong>HEX</strong>&gt;<br/>
（事务元标识符）00 01 （协议标识符）00 00 （数据长度）00 06 （站号）01 （功能码）03 （起始地址）00 00 （读取寄存器数量）00 0A</p>
<p>响应命令：RECV <strong>HEX</strong>&gt;<br/>
（事务元标识符）00 01 （协议标识符）00 00 （数据长度）00 17 （站号）01 （功能码）03 （字节数）14 （读取的各个寄存器值）00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0A</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9003.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9003.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9003.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9003.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave例子03.png"
        title="ModbusSlave03" /></p>
<h3 id="功能码-0x10-命令格式解析">功能码 0x10 命令格式解析</h3>
<p>请求命令格式</p>
<table>
<thead>
<tr>
<th></th>
<th>大小</th>
<th>取值范围</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>事务元标识符</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>协议标识符</td>
<td>2 byte</td>
<td>固定值0x0000</td>
<td>Modbus协议</td>
</tr>
<tr>
<td>数据长度</td>
<td>2 byte</td>
<td>0x0003 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>单元标识符（站号）</td>
<td>1 byte</td>
<td>0x01 至 0xFF</td>
<td>默认值为1，一般无需变化</td>
</tr>
<tr>
<td>功能码</td>
<td>1 byte</td>
<td>0x10</td>
<td></td>
</tr>
<tr>
<td>起始地址</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>寄存器数量（N）</td>
<td>2 byte</td>
<td>0x0000 至 0x007D</td>
<td></td>
</tr>
<tr>
<td>字节数</td>
<td>1 byte</td>
<td>2 * N</td>
<td>寄存器值所包括的字节数</td>
</tr>
<tr>
<td>寄存器值</td>
<td>2 * N byte</td>
<td>数据值</td>
<td>1个寄存器占用2个字节</td>
</tr>
</tbody>
</table>
<p><strong>注：<em>N = 寄存器数量</em></strong></p>
<p>响应命令格式</p>
<table>
<thead>
<tr>
<th></th>
<th>大小</th>
<th>取值范围</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>事务元标识符</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>协议标识符</td>
<td>2 byte</td>
<td>固定值0x0000</td>
<td>Modbus协议</td>
</tr>
<tr>
<td>数据长度</td>
<td>2 byte</td>
<td>0x0003 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>单元标识符（站号）</td>
<td>1 byte</td>
<td>0x01 至 0xFF</td>
<td>默认值为1，一般无需变化</td>
</tr>
<tr>
<td>功能码</td>
<td>1 byte</td>
<td>0x03</td>
<td></td>
</tr>
<tr>
<td>起始地址</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>寄存器数量（N）</td>
<td>2 byte</td>
<td>0x0000 至 0x007D</td>
<td></td>
</tr>
</tbody>
</table>
<p>错误响应格式</p>
<table>
<thead>
<tr>
<th></th>
<th>大小</th>
<th>取值范围</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>事务元标识符</td>
<td>2 byte</td>
<td>0x0000 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>协议标识符</td>
<td>2 byte</td>
<td>固定值0x0000</td>
<td>Modbus协议</td>
</tr>
<tr>
<td>数据长度</td>
<td>2 byte</td>
<td>0x0003 至 0xFFFF</td>
<td></td>
</tr>
<tr>
<td>单元标识符（站号）</td>
<td>1 byte</td>
<td>0x01 至 0xFF</td>
<td>默认值为1，一般无需变化</td>
</tr>
<tr>
<td>错误码</td>
<td>1 byte</td>
<td>0x90</td>
<td>0x80 + 0x10</td>
</tr>
<tr>
<td>异常码</td>
<td>1 byte</td>
<td>0x01 至 0x04</td>
<td>0x01：该功能码不支持 <br/> 0x02：起始地址不支持 或者 起始地址+寄存器数量不支持 <br/> 0x03：读取寄存器数量不支持 <br/> 0x04：读取寄存器失败</td>
</tr>
</tbody>
</table>
<h4 id="eg使用-功能码0x10-写入-站号01-地址0x00000x0009-的数据">eg.使用 功能码0x10 写入 站号01 地址0x0000~0x0009 的数据</h4>
<p>请求命令：SEND <strong>HEX</strong> &gt;<br/>
（事务元标识符）00 05 （协议标识符）00 00 （数据长度）00 1B （站号）01 （功能码）10 （起始地址）00 00 （写入寄存器数量）00 0A （字节数）14 00 （各个寄存器的写入值）0A 00 14 00 1E 00 28 00 32 00 3C 00 46 00 50 00 5A 00 64</p>
<p>响应命令：RECV <strong>HEX</strong> &gt;<br/>
（事务元标识符）00 05 （协议标识符）00 00 （数据长度）00 06 （站号）01 10 （起始地址）00 00 （寄存器数量）00 0A</p>
<p><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9010.png"
        data-srcset="https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9010.png, https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9010.png 1.5x, https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave%e4%be%8b%e5%ad%9010.png 2x"
        data-sizes="auto"
        alt="https://gitee.com/jacobcj/blog-pic/raw/master/blog/ModbusSlave例子10.png"
        title="ModbusSlave10" /></p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2023-08-23</span>
            </div></div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/modbustcp/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw" aria-hidden="true"></i>&nbsp;<a href="/tags/modbus/">modbus</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav"><a href="/modbus/" class="prev" rel="prev" title="Modbus协议——ModbusRTU、ModbusASCII"><i class="fas fa-angle-left fa-fw" aria-hidden="true"></i>Modbus协议——ModbusRTU、ModbusASCII</a>
            <a href="/ethercat_01summary/" class="next" rel="next" title="EtherCAT从会到不会——概述（1）">EtherCAT从会到不会——概述（1）<i class="fas fa-angle-right fa-fw" aria-hidden="true"></i></a></div>
</div>
</article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.115.4">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.11"><i class="far fa-kiss-wink-heart fa-fw" aria-hidden="true"></i> LoveIt</a>
                </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw" aria-hidden="true"></i><span itemprop="copyrightYear">2023 - 2024</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">Jacob Chen</a></span>&nbsp;|&nbsp;<span class="license"><a rel="license external nofollow noopener noreffer" href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw" aria-hidden="true"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw" aria-hidden="true"></i>
            </a>
        </div><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/autocomplete.js@0.38.1/dist/autocomplete.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lunr@2.3.9/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/lazysizes@5.3.2/lazysizes.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clipboard@2.0.11/dist/clipboard.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":50},"comment":{},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":30,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
